const { Service } = require('egg');

class BlogService extends Service {
    async create({ title, content, uid }) {
        return this.app.mysql.query(
            'insert into blog (title, content, uid, create_time) values (?, ?, ?, ?)',
            [title, content, uid, new Date()],
        );
    }

    async readList() {
        let sql = `
            select b.id, b.title, b.content, b.create_time, u.nickname 
            from blog as b 
            join user as u on b.uid = u.id
        `;
        return await this.app.mysql.query(sql);
        // [
        //     {

        //     },
        //     {

        //     },
        //     {

        //     }
        // ]
    }
}

module.exports = BlogService;
